package com.endava.nio_io.exercises;

import java.io.IOException;

/*	Write a object read/write program that
 *	reads/writes a couple of Shape objects (e.g. Square, Circle, Rectangle)
 *	to disk
 */
/**
 * @author adumitrescu
 * 
 */
public class Ex1 {

	public static void main(String[] args) throws IOException,
			ClassNotFoundException {

		// File f = new File("objects.dat");
		// if (f.exists() == false) {
		// f.createNewFile();
		// } else {
		// System.out.println(f);
		// }

		Square square = new Square(10);
		Circle circle = new Circle(1);
		Rectangle rectangle = new Rectangle(10, 20);
		Triangle triangle = new Triangle(10, 10, 10);
		DateForObjects date = new DateForObjects();

		ShapeUtil shapeUtil = new ShapeUtil();
		shapeUtil.writeShapes(circle);
		shapeUtil.writeShapes(triangle);
		shapeUtil.writeShapes(rectangle);
		shapeUtil.writeShapes(square);

		shapeUtil.readShapes();
		System.out.println("Circle Radius: " + circle.getRadius());
		System.out.println("Trinagle first line: " + triangle.getLine1());
		System.out.println("Trinagle second line: " + triangle.getLine2());
		System.out.println("Trinagle thirs line: " + triangle.getLine3());
		System.out.println("Rectangle's length= " + rectangle.getLength());
		System.out.println("Rectangle's width= " + rectangle.getWidth());
		System.out.println("Square's Line= " + square.getLine());
		System.out.println(date.getDate());

		// FileOutputStream fos = new FileOutputStream("objects.dat");
		// ObjectOutputStream oos = new ObjectOutputStream(fos);
		// oos.writeObject(square);// write this square object to disk
		// oos.writeObject(circle);
		// oos.writeObject(rectangle);
		// oos.writeObject(triangle);
		// oos.writeObject(new Date());// write today's date to disk
		// oos.close();// close file
		//
		// FileInputStream fis = new FileInputStream("objects.dat");
		// ObjectInputStream ois = new ObjectInputStream(fis);
		// Square mySquare = (Square) ois.readObject();// read square from disk
		// Circle myCircle = (Circle) ois.readObject();
		// Rectangle myRectangle = (Rectangle) ois.readObject();
		// Triangle myTriangle = (Triangle) ois.readObject();
		//
		// Date today = (Date) ois.readObject();// read date object from disk
		// ois.close();// close file
		//
		// System.out.println(mySquare.getLine());
		// System.out.print(mySquare);
		//
		// System.out.println(myCircle);
		//
		// System.out.println(myRectangle);
		//
		// System.out.println(myTriangle);
		//
		// System.out.println(today);

	}
}
